<?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model{
    //自动验证 直接写数据库字段名
    //如果表单里面名和数据库字段名不一致，做字段映射
    protected $_validate = array(
        array('username','require','用户名必须！'),
        array('password','require','密码必须！'),
        array('password','/^[\w-*&……%￥#@！]{6,15}$/','密码格式错误！',1, 'regex'),
    );
    /**
     * 判断用户名密码是否一致
     */
    function checkUserExits(){
        $whereArr = array(
            'username' => $this->username,
            'password' => md5($this->password)
        );
        $data = $this->field('Id,username,password,email')->where($whereArr)->find();
        if(empty($data)){
            return false;
        }else{
            if($this->userName == $data['userName']){
                return $data;
            }else{
                return false;
            }
        }
    }
}

?>